package gov.kqqzyyy.monkey.orderpad.dialogFragment;

import android.app.Activity;
import android.app.DialogFragment;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.google.android.material.textfield.TextInputEditText;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.socks.library.KLog;

import gov.kqqzyyy.monkey.orderpad.R;

/**
 * Created by Monkey on 2018/1/8.
 * 账号确认
 */

public class LoginConfirmDialog extends DialogFragment implements View.OnClickListener {

    TextView accountText;
    TextInputEditText inputEditText;
    Button loginBTN;
    Button cancelBTN;

    private String loginAccount;
    private String loginPW;

    private Activity activity;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        getDialog().setTitle("账号确认");
        View dialogView = inflater.inflate(R.layout.dialog_patient_login, container, false);
        onBindDialogUI(dialogView);
        activity = getActivity();
//        accountText.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
//        accountText.getPaint().setAntiAlias(true);//抗锯齿
        accountText.setText(loginAccount);
        loginBTN.setOnClickListener(this);
        cancelBTN.setOnClickListener(this);
        return dialogView;
    }

    public void setLoginAccount(String loginAccount) {
        this.loginAccount = loginAccount;
    }

    public void setLoginPW(String loginPW) {
        this.loginPW = loginPW;
    }

    private void onBindDialogUI(View view) {
        accountText = view.findViewById(R.id.dialog_login_account);
        inputEditText = view.findViewById(R.id.dialog_patient_password_InputEditText);
        loginBTN = view.findViewById(R.id.dialog_login_btn);
        cancelBTN = view.findViewById(R.id.dialog_cancel_btn);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_login_btn:
                String inputPWD = inputEditText.getText().toString();
                if (inputPWD.equals(loginPW)) {
                    KLog.d("APE", "confirm success , do cancel or pay");
//                    ((OrderCheckActivity2) activity).doCancelOrPayTask();

                    getDialog().dismiss();
                } else {
                    Toast toast = Toast.makeText(activity, "密码错误，请重新输入", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.TOP, 0, 100);
                    TextView textView = toast.getView().findViewById(android.R.id.message);
                    textView.setTextSize(32);
                    toast.show();
                    inputEditText.requestFocus();
                }
                break;
            case R.id.dialog_cancel_btn:
                getDialog().dismiss();
                break;
        }
    }
}
